import instance from "./request";

// 获取角色 列表
function getRoles() {
    return instance.get("roles");
}
// 添加角色
function addRole(data) {
    return instance.post("roles", data);
}
// 删除角色
function deleteRole(id) {
    return instance.delete(`roles/${id}`);
}
// 编辑提交
function editRole(obj) {
    let {id,roleName,roleDesc}=obj
    return instance.put(`roles/${id}`,{roleName,roleDesc});
}

// 所有权限
function getPermissions(type) {
    return instance.get(`rights/${type}`);
}
// 角色授权
function  RoleAuthorization(params){
    return instance.post(`roles/${params.roleId}/rights`,{'rids':params.rids})
}
// 删除角色
function deleteRoleAuthorization(params){
    let {roleid,id}=params
    console.log(roleid,id);
    // roles/:roleId/rights/:rightId
    return instance.delete(`roles/${roleid}/rights/${id}`)
}

export {
    getRoles,
    addRole,
    deleteRole,
    editRole,
    getPermissions,
    RoleAuthorization,
    deleteRoleAuthorization
}
